package com.quanyan.stadium.web.api;

import com.quanyan.api.APIResponse;
import com.quanyan.orderpay.response.mq.OrderNotifyMsg;
import com.quanyan.orderpay.response.mq.RefundNotifyMsg;
import com.quanyan.stadium.service.gameSign.GameSignUpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA.
 * User: zyq
 * Date: 2016/8/5 0005
 * Time: 14:24
 */
@RestController
@RequestMapping("/api/stadium/callback/")
public class CallBackController {

    @Autowired
    private GameSignUpService gameSignUpService;

    private final static Logger logger = LoggerFactory.getLogger(CallBackController.class);

    /**
     * 支付回调
     * @param orderNotifyMsg
     * @param request
     */
    @RequestMapping(value="/payCallback", method = RequestMethod.POST)
    public APIResponse payCallback(@RequestBody OrderNotifyMsg orderNotifyMsg,HttpServletRequest request)  {
        logger.info("支付回调开始,当前订单号: {}, 用户ID:{}", orderNotifyMsg.getOutTradeNo(), orderNotifyMsg.getUid());
        return gameSignUpService.orderPayOperate(orderNotifyMsg);
    }

    /**
     * 支付超时回调
     * @param orderNotifyMsg
     * @param request
     */
    @RequestMapping(value="/expireCallBack", method = RequestMethod.POST)
    public APIResponse expireCallBack(@RequestBody OrderNotifyMsg orderNotifyMsg,HttpServletRequest request)  {
        logger.info("支付超时回调开始,当前订单号: {}, 用户ID:{}", orderNotifyMsg.getOutTradeNo(), orderNotifyMsg.getUid());
         return gameSignUpService.expireCallBack(orderNotifyMsg.getOutTradeNo());
    }

    /**
     * 退款回调
     * @param
     * @return
     */
    @RequestMapping(value="/refundCallback", method = RequestMethod.POST)
    public APIResponse<?> refundCallback(@RequestBody RefundNotifyMsg RefundNotifyMsg)  {
        gameSignUpService.refundCallback(RefundNotifyMsg);
        return APIResponse.returnSuccess();
    }



}
